/*
package study;

import java.io.BufferedReader;
import java.text.MessageFormat;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class IndexController {

    @RequestMapping("/hello")
    public String hello(HttpServletRequest request,HttpServletResponse response){

        */
/**
         * HttpServletRequest对象代表客户端的请求,当客户端通过http协议请求访问
         * 服务器的时候,http请求头的所有信息都封装在这个对象中，通过这个对象，可以获取
         * 客户端请求的所有信息.
         * http请求包含请求行/状态行、请求头、请求体
         *//*

        //客户端请求uri
        String uri = request.getRequestURI();
        //客户端请求行中的参数部分
        String queryString = request.getQueryString();
        //返回url的额外路径信息
        String pathInfo = request.getPathInfo();
        //客户端ip
        String ip = request.getRemoteAddr();
        //客户端完整主机名
        String host = request.getRemoteHost();
        //客户端端口
        int port = request.getRemotePort();
        //获取web服务器的主机和端口,主机名
        String webHost = request.getLocalAddr();
        int webPort = request.getLocalPort();
        String webName = request.getLocalName();
        //获取请求头信息
        Enumeration<String> headers = request.getHeaderNames();
        System.out.println("请求头信息");
        while(headers.hasMoreElements()){
            String headName = (String)headers.nextElement();
            String headValue = request.getHeader(headName);
            System.out.println(headName+"："+headValue);
        }
        System.out.println("请求参数");
        //request如果是post才有请求体，get则没有请求体，直接跟在？后面，用&隔开
        */
/**
         * getHeader(String name)获取单个请求头name对应的value
         * getHeaders(String name)获取多个请求头对应的一组value，因此返回的是枚举类型的数据
         * getHeaderNames()获取请求头的所有name值，返回的数据也是一个枚举类型数据，将枚举中的元素遍历出来，根据name取到value，即是请求头的所有信息
         *//*

        //获取客户端请求参数
        //request对象封装的参数是以Map的形式存储的
        Map<String, String[]> paramMap = request.getParameterMap();
        for(Map.Entry<String, String[]> entry :paramMap.entrySet()){
            String paramName = entry.getKey();
            StringBuilder paramValue = new StringBuilder();
            String[] paramValueArr = entry.getValue();
            for (int i = 0; paramValueArr!=null && i < paramValueArr.length; i++) {
                if (i == paramValueArr.length-1) {
                    paramValue.append(paramValueArr[i]);
                }else {
                    paramValue.append(paramValueArr[i]).append(",");
                }
            }
            System.out.println(MessageFormat.format("{0}={1}", paramName, paramValue.toString()));
        }
        //请求体
        try {
            System.out.println("请求体");
            charReader(request);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return "hello world";
    }

    void charReader(HttpServletRequest request) throws Exception{
        BufferedReader br = request.getReader();
        String str;
        StringBuilder wholeStr = new StringBuilder();
        while((str = br.readLine()) != null){
            wholeStr.append(str);
        }
        System.out.println(wholeStr);
    }
}*/
